package com.j.lemon.learn.onlytest;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;

/**
 * @Author lijunjun
 * @Date 2019-05-22 18:13
 * @Description
 */
public class TTTT {
    public static void main(String[] args) {
//        String start = "河南焦作新华街供应处家属院";
//        String end = "河南焦作解放区供应处家属院";
//
//
//        String startLonLat = getLonLat(start);
//        String endLonLat = getLonLat(end);
//
//        System.out.println(startLonLat);
//        System.out.println(endLonLat);
//        Long dis = getDistance(startLonLat, endLonLat);
//        System.out.println(dis);
//        int a = 100;
//        String s = String.valueOf(a);
//
//        for (int i = 0; i < s.length(); i++) {
//            char c = s.charAt(i);
//            String integer = String.valueOf(c);
//            System.out.println(integer);
//        }

        System.out.println(Math.pow(10,0));
    }

    private static String getLonLat(String address) {
        //返回输入地址address的经纬度信息, 格式是 经度,纬度
        String queryUrl = "http://restapi.amap.com/v3/geocode/geo?key=2fb14b84cd5bfc260beef009d9be4880&address=" + address;
        String queryResult = getResponse(queryUrl);  //高德接口返回的是JSON格式的字符串

        JSONObject jo = JSONObject.parseObject(queryResult);
        JSONArray ja = jo.getJSONArray("geocodes");
        return JSONObject.parseObject(ja.getString(0)).get("location").toString();
    }

    private static Long getDistance(String startLonLat, String endLonLat) {
        //返回起始地startAddr与目的地endAddr之间的距离，单位：米
        String queryUrl = "http://restapi.amap.com/v3/distance?key=2fb14b84cd5bfc260beef009d9be4880&origins=" + startLonLat + "&destination=" + endLonLat;
        String queryResult = getResponse(queryUrl);
        JSONObject jo = JSONObject.parseObject(queryResult);
        JSONArray ja = jo.getJSONArray("results");

        return Long.parseLong(JSONObject.parseObject(ja.getString(0)).get("distance").toString());
    }

    private static String getResponse(String serverUrl) {
        StringBuilder result = new StringBuilder();
        try {
            URL url = new URL(serverUrl);
            URLConnection conn = url.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                result.append(line);
            }
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result.toString();
    }

}
